

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>foampy.tests.test_core &mdash; foamPy 0.0.5 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../../../genindex.html"/>
        <link rel="search" title="Search" href="../../../search.html"/>
    <link rel="top" title="foamPy 0.0.5 documentation" href="../../../index.html"/>
        <link rel="up" title="Module code" href="../../index.html"/> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> foamPy
          

          
          </a>

          
            
            
              <div class="version">
                0.0.5
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">foamPy</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>foampy.tests.test_core</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for foampy.tests.test_core</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;Tests for core foamPy functions.&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">,</span> <span class="n">absolute_import</span>
<span class="kn">import</span> <span class="nn">foampy</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>


<div class="viewcode-block" id="test_load_all_torque_drag"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_load_all_torque_drag">[docs]</a><span class="k">def</span> <span class="nf">test_load_all_torque_drag</span><span class="p">():</span>
    <span class="n">t</span><span class="p">,</span> <span class="n">torque</span><span class="p">,</span> <span class="n">drag</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">load_all_torque_drag</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">==</span> <span class="mf">4.0</span></div>


<div class="viewcode-block" id="test_gen_dynmeshdict"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_gen_dynmeshdict">[docs]</a><span class="k">def</span> <span class="nf">test_gen_dynmeshdict</span><span class="p">():</span>
    <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="n">u</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">r</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">meantsr</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">foampy</span><span class="o">.</span><span class="n">gen_dynmeshdict</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">meantsr</span><span class="p">,</span> <span class="n">npoints</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">rpm_fluc</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">t</span><span class="p">,</span> <span class="n">theta</span><span class="p">,</span> <span class="n">omega</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">load_theta_omega</span><span class="p">()</span>
    <span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span>
    <span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">==</span> <span class="mf">0.5</span>
    <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">omega</span><span class="p">)</span> <span class="o">==</span> <span class="mi">10</span>
    <span class="k">assert</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">omega</span><span class="o">*</span><span class="n">r</span><span class="o">/</span><span class="n">u</span><span class="p">)</span> <span class="o">==</span> <span class="n">meantsr</span>
    <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="s2">&quot;../&quot;</span><span class="p">)</span>
    <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span><span class="s2">&quot;git checkout test/constant/dynamicMeshDict&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="test_run"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_run">[docs]</a><span class="k">def</span> <span class="nf">test_run</span><span class="p">():</span>
    <span class="n">foampy</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;blockMesh&quot;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-help&quot;</span><span class="p">],</span> <span class="n">tee</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="s2">&quot;log.blockMesh&quot;</span><span class="p">)</span>
    <span class="n">foampy</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;blockMesh&quot;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-help&quot;</span><span class="p">],</span> <span class="n">tee</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">foampy</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;blockMesh&quot;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-help&quot;</span><span class="p">],</span> <span class="n">tee</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
    <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s2">&quot;log.blockMesh&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="test_run_parallel"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_run_parallel">[docs]</a><span class="k">def</span> <span class="nf">test_run_parallel</span><span class="p">():</span>
    <span class="n">foampy</span><span class="o">.</span><span class="n">run_parallel</span><span class="p">(</span><span class="s2">&quot;blockMesh&quot;</span><span class="p">,</span> <span class="n">nproc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-help&quot;</span><span class="p">],</span> <span class="n">tee</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="s2">&quot;log.blockMesh&quot;</span><span class="p">)</span>
    <span class="n">foampy</span><span class="o">.</span><span class="n">run_parallel</span><span class="p">(</span><span class="s2">&quot;blockMesh&quot;</span><span class="p">,</span> <span class="n">nproc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-help&quot;</span><span class="p">],</span> <span class="n">tee</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                        <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s2">&quot;log.blockMesh&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="test_get_n_processors"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_get_n_processors">[docs]</a><span class="k">def</span> <span class="nf">test_get_n_processors</span><span class="p">():</span>
    <span class="n">n</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">get_n_processors</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">6</span></div>


<div class="viewcode-block" id="test_summary"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_summary">[docs]</a><span class="k">def</span> <span class="nf">test_summary</span><span class="p">():</span>
    <span class="n">s</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">summary</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">s</span><span class="o">.</span><span class="n">delta_t</span> <span class="o">==</span> <span class="mf">2e-4</span></div>


<div class="viewcode-block" id="test_get_solver_times"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_get_solver_times">[docs]</a><span class="k">def</span> <span class="nf">test_get_solver_times</span><span class="p">():</span>
    <span class="n">td</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">get_solver_times</span><span class="p">(</span><span class="n">log_fpath</span><span class="o">=</span><span class="s2">&quot;test/log.icoFoam&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">td</span><span class="p">[</span><span class="s2">&quot;time&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.04</span>
    <span class="k">assert</span> <span class="n">td</span><span class="p">[</span><span class="s2">&quot;clocktime&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span>
    <span class="k">assert</span> <span class="n">td</span><span class="p">[</span><span class="s2">&quot;exectime&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.02</span></div>


<div class="viewcode-block" id="test_read_dict"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_read_dict">[docs]</a><span class="k">def</span> <span class="nf">test_read_dict</span><span class="p">():</span>
    <span class="n">d</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">read_dict</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">,</span> <span class="n">dictname</span><span class="o">=</span><span class="s2">&quot;controlDict&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;application&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;pimpleDyMFoam&quot;</span></div>


<div class="viewcode-block" id="test_load_forces"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_load_forces">[docs]</a><span class="k">def</span> <span class="nf">test_load_forces</span><span class="p">():</span>
    <span class="n">df</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">load_forces</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">df</span><span class="o">.</span><span class="n">time</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mf">2e-3</span></div>


<div class="viewcode-block" id="test_load_probes_data"><a class="viewcode-back" href="../../../foampy.tests.html#foampy.tests.test_core.test_load_probes_data">[docs]</a><span class="k">def</span> <span class="nf">test_load_probes_data</span><span class="p">():</span>
    <span class="n">df</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">load_probes_data</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">df</span><span class="p">)</span>
    <span class="n">df2</span> <span class="o">=</span> <span class="n">foampy</span><span class="o">.</span><span class="n">load_probes_data</span><span class="p">(</span><span class="n">casedir</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">,</span> <span class="n">field_name</span><span class="o">=</span><span class="s2">&quot;p&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">df2</span><span class="p">)</span></div>
</pre></div>

           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, Pete Bachant.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'0.0.5',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>